package BIZ;

import DAO.UserDetailsDAO;
import javabean.userDetails;

public class UserBiz {
    //UserDao
    UserDetailsDAO userDao = new UserDetailsDAO();
    statementofncomeBiz statementofncomeBiz = new statementofncomeBiz();
    totalFeeBiz totalFeeBiz=new totalFeeBiz();


    public userDetails getUser(String userId, String userPwd) {
        return userDao.searchManager(userId, userPwd);

    }

    public userDetails getuser(String userId, String userPwd) {
        return userDao.searchUser(userId, userPwd);

    }

    //得到用户密码
    public String getpwd(String userid) {
        return userDao.getUserBY(userid).getPassword();
    }

    //得到用户类型
    public String getusertype(String userid) {

        long type = userDao.getUserBY(userid).getStatus();


        return type + "";
    }


    //得到电话
    public String getuserphone(String userid) {

        String phone = userDao.getUserBY(userid).getPhone();


        return phone;
    }

    //得到余额
    public String getuserbalance(String userid) {

        long balance = userDao.getUserBY(userid).getAccountBalance();


        return balance + "";
    }

    //获得注册时间
    public String getRegdate(String userid) {
        String registrationTime = userDao.getUserBY(userid).getRegistrationDate();
        return registrationTime;
    }

    //获得车牌号
    public String getCarId1(String userid) {
        String carId = userDao.getUserBY(userid).getCarId1();
        return carId;
    }

    public String getCarId2(String userid) {
        String carId = userDao.getUserBY(userid).getCarId2();
        return carId;
    }

    public String getCarId3(String userid) {
        String carId = userDao.getUserBY(userid).getCarId3();
        return carId;
    }

    //获得邮箱
    public String getEmail(String userid) {
        String Email = userDao.getUserBY(userid).getEmail();
        return Email;
    }

    //获得剩余天数
    public String getRemainDay(String userid) {
        long getRemainDay = userDao.getUserBY(userid).getRemainingDays();
        return getRemainDay + "";
    }

    //获得剩余次数
    public String getRemainDegree(String userid) {
        long getRemainDegree = userDao.getUserBY(userid).getRemainingDegrees();
        return getRemainDegree + "";
    }


    //用户注册
    public long reg(String name, String pwd, String email, String phone, String carId, String type) {


        long reg1 = userDao.RegisterUser(name, pwd, email, phone, carId, Integer.parseInt(type));
        return reg1;
    }

    //用户修改密码
    public boolean ChangePassword(String pwd, String userid) {
        boolean isorno = userDao.ChangePassword(pwd, userid);
        return isorno;
    }

    //用户修改电话
    public boolean ChangePhone(String phone, String userid) {
        boolean isorno = userDao.ChangePhone(phone, userid);
        return isorno;
    }

    //用户修改邮箱
    public int ChangeEmail(String email, String userid) {
        int isorno = userDao.ChangeEmail(email, userid);
        return isorno;
    }

    //用户修改绑定车牌号
    public int ChangeCar1(String car1, String userid) {
        int isorno = userDao.ChangeCarID1(car1, userid);
        return isorno;
    }

    public int ChangeCar2(String car2, String userid) {
        int isorno = userDao.ChangeCarID2(car2, userid);
        return isorno;
    }

    public int ChangeCar3(String car3, String userid) {
        int isorno = userDao.ChangeCarID3(car3, userid);
        return isorno;
    }


    //进行用户 n 天/次停车 的充值
    public String addremain1(String count, String userid, String remainday, String carid1, String carid2, String carid3, String Type) {

        boolean x = false;//执行更新参数
        String newremain = null;
        String newbalance;
        int change;
        if (Type.equals("0")) {
            //计算花费
            String cost = ((Integer.parseInt(count)) * 300) + "";

            //修改账户余额
            newbalance = statementofncomeBiz.Refundorcost(userid, cost);

            //修改月卡总收入
            change=totalFeeBiz.allmonthincome(cost);



            //得到当前天数
            String nowday=getRemainDay(userid);
            //得出新的剩余天数
            newremain = ((Integer.parseInt(count) * 30) + Integer.parseInt(remainday) +Integer.parseInt(nowday))+ "";
            //更新剩余天数
            x = userDao.UpdateTimes(newremain, userid);

            //将消费记录存入账单
            cost = (0 - Integer.parseInt(cost)) + "";
            int addbill = statementofncomeBiz.addbill(userid, carid1, carid2, carid3, cost);
        }
        if (Type.equals("1")) {
            //计算花费
            String cost = ((Integer.parseInt(count)) * 12) + "";

            //修改账户余额
            newbalance = statementofncomeBiz.Refundorcost(userid, cost);

            //修改次卡总收入
            change=totalFeeBiz.alldegreeincome(cost);

            //得到当前次数
            String nowdegree=getRemainDay(userid);
            //得出新的剩余次数
            newremain = (Integer.parseInt(count) + Integer.parseInt(remainday) +Integer.parseInt(nowdegree))+ "";
            x = userDao.UpdateDegrees(newremain, userid);

            //将消费记录存入账单
            cost = (0 - Integer.parseInt(cost)) + "";
            int addbill = statementofncomeBiz.addbill(userid, carid1, carid2, carid3, cost);
        }


        return newremain;

    }

    //在上一步的基础上返回剩余余额
    public String addremain2(String count, String userid, String remainday, String carid1, String carid2, String carid3, String Type) {

        boolean x = false;//执行更新参数
        String newremain;
        String newbalance = null;
        if (Type.equals("0")) {
            //计算花费
            String cost = ((Integer.parseInt(count)) * 300) + "";

            //修改账户余额
            newbalance = statementofncomeBiz.Refundorcost(userid, cost);

        }
        if (Type.equals("1")) {
            //计算花费
            String cost = ((Integer.parseInt(count)) * 6) + "";

            //修改账户余额
            newbalance = statementofncomeBiz.Refundorcost(userid, cost);
        }

        return newbalance;

    }

    //退次数或天数并改变余额
    public boolean changeremaindayordegree(String shengyu,String Type,String userid,String balance) {


        if (Type.equals("0")) {
            String return1 = ((Integer.parseInt(shengyu)) * 10) + "";

            //计算退后的余额
            int newBalance1 = (Integer.parseInt(balance) - Integer.parseInt(return1));
            String newBalance = newBalance1 + "";
            //修改账户余额
            boolean x = userDao.UpdateBalance(newBalance, userid);

            //得出新的剩余天数
            String newremain = "0";
            //更新剩余天数
            boolean y = userDao.UpdateTimes(newremain, userid);
        }
        if (Type.equals("1")) {
            String return1 = ((Integer.parseInt(shengyu)) * 5) + "";

            //计算退后的余额
            int newBalance1 = (Integer.parseInt(balance) - Integer.parseInt(return1));
            String newBalance = newBalance1 + "";
            //修改账户余额
            boolean x = userDao.UpdateBalance(newBalance, userid);

            //得出新的剩余次数
            String newremain = "0";
            //更新剩余次数
            boolean y = userDao.UpdateDegrees(newremain, userid);


        }
        return true;

    }


}

